/**
 * Created by George on 2014/9/14.
 */
'use strict';

var mysql = require('../common/mysql.js');

/*
 @todo 判断tagid对应标签是否存在
 */
exports.isTagExist = function*(tagid) {
    var isExit = false;
    var result = yield mysql.query('SELECT tagid FROM mh_tags WHERE tagid=?', [tagid]);
    if (result.length > 0) {
        isExit = true;
    }
    return isExit;
};
/*
 @todo 获取标签信息
 @fields 查找字段 格式为field1，field2...
 @where  查找条件 格式为field1=? and field=?
 @values 条件值   格式为[value1，value2]
 */
exports.getTags = function*(fields, where, values) {
    var sql = "select " + fields + " from mh_tags where " + where;
    var tags = yield mysql.query(sql, values);
    if (tags.length > 0) {
        return tags;
    }
    return [];
};
/*
 @todo 获取订阅标签
 @fields 查找字段 格式为field1，field2...
 @where  查找条件 格式为field1=? and field=?
 @values 条件值   格式为[value1，value2]
 */
exports.getPinTags = function*(fields, where, values) {
    var sql = "select " + fields + " from mh_pintag where " + where;
    var pinTags = yield mysql.query(sql, values);
    if (pinTags != '') {
        return pinTags;
    }
    return [];
};
